<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			div {
				width: 1000px;
				height: 500px;
				text-align: center;
				border: 2px solid;
			}
		</style>
	</head>

	<body>
		<div>
			<canvas id="Mycanvas" width="1000px" height="500px"></canvas>
			<script type="text/javascript">
				var canvas = document.getElementById("Mycanvas");
				var ctx = canvas.getContext("2d");
				var rot = 0;
				var r = 100;
				var leftx = 250;
				var xuanzhuanjd = 5;
				var huchang = 5 * Math.PI * r / 180;

				setInterval(function() {
					var x = Math.cos(rot / 180 * Math.PI) * 0.5 * r;
					var y = Math.sin(rot / 180 * Math.PI) * 0.5 * r;
					ctx.clearRect(0, 0, 1000, 500);
					ctx.beginPath();
					ctx.fillStyle = "yellowgreen";
					ctx.fillRect(0, 0, 1000, 500);

					ctx.beginPath();
					ctx.arc(leftx, 250, r, (rot / 180) * Math.PI, (1 + rot / 180) * Math.PI, true);
					ctx.fillStyle = "black";
					ctx.fill();
					ctx.beginPath();
					ctx.arc(leftx, 250, r, (rot / 180) * Math.PI, (1 + rot / 180) * Math.PI);
					ctx.fillStyle = "white";
					ctx.fill();

					ctx.beginPath();
					ctx.arc(leftx-x, 250 - y, 0.5 * r, 0, 2 * Math.PI);
					ctx.fillStyle = "black";
					ctx.fill();
					ctx.beginPath();
					ctx.arc(leftx+x, 250 + y, 0.5 * r, 0, 2 * Math.PI);
					ctx.fillStyle = "white";
					ctx.fill();

					ctx.beginPath();
					ctx.arc(leftx-x, 250 - y, 0.1 * r, 0, 2 * Math.PI);
					ctx.fillStyle = "white";
					ctx.fill();
					ctx.beginPath();
					ctx.arc(leftx+x, 250 + y, 0.1 * r, 0, 2 * Math.PI);
					ctx.fillStyle = "black";
					ctx.fill();

					rot = rot + xuanzhuanjd;
					leftx = leftx + huchang;
					if(leftx > 1000 - huchang || leftx < 200 )
					{huchang = -huchang;
					xuanzhuangjd = -xuanzhuanjd;}

				}, 50)
			</script>
		</div>
	</body>

</html>